package com.example.fasttask;

import java.lang.reflect.Field;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.provider.BaseColumns;
import android.util.Log;
import android.util.SparseArray;

public class TasksContentDB extends ContentProvider {
	private static final String DATABASE_NAME = "TasksDB";
	private static final int DATABASE_VERSION = 1;
	public static final String TABLE_COMMENTS = "comments";
	SQLiteOpenHelper mHelper;
	private UriMatcher mUriMatcher;
	SparseArray<String> mMimeTypes;

	protected static class TasksContentDBHelper extends SQLiteOpenHelper {
		TasksContentDBHelper(Context paramContext) {
			super(paramContext, DATABASE_NAME, null, DATABASE_VERSION);
		}

		private String createTableQueryFromArray(String paramString,
				String[][] paramArrayOfString) {
			StringBuilder localStringBuilder = new StringBuilder();
			localStringBuilder.append("CREATE TABLE ");
			localStringBuilder.append(paramString);
			localStringBuilder.append(" (");
			int i = paramArrayOfString.length;
			for (int j = 0;; j++) {
				if (j >= i) {
					localStringBuilder
					.setLength(localStringBuilder.length() - 1);
					localStringBuilder.append(");");
					return localStringBuilder.toString();
				}
				String[] arrayOfString = paramArrayOfString[j];
				localStringBuilder.append(' ');
				localStringBuilder.append(arrayOfString[0]);
				localStringBuilder.append(' ');
				localStringBuilder.append(arrayOfString[1]);
				localStringBuilder.append(',');
			}
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			Class<?>[] arrayOfClass = TasksContentDB.class
					.getDeclaredClasses();
			int numClasses = arrayOfClass.length;
			for (int i = 0; i < numClasses; i++) {
				Class<?> localClass = arrayOfClass[i];
				if (BaseColumns.class.isAssignableFrom(localClass)) {
					try {
						Field localField1 = localClass
								.getDeclaredField("SCHEMA");
						Field localField2 = localClass
								.getDeclaredField("TABLE_NAME");
						String[][] arrayOfString = (String[][]) localField1
								.get(null);
						db.execSQL(createTableQueryFromArray(
								(String) localField2.get(null), arrayOfString));
					} catch (Exception localException) {
						while (true)
							localException.printStackTrace();
					}
				}
			}

		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			Class<?>[] arrayOfClass = TasksContentDB.class
					.getDeclaredClasses();
			Log.w(TasksContentDB.class.getName(),
					"Upgrading database from version " + oldVersion + " to "
							+ newVersion + ", which will destroy all old data");
			int numClasses = arrayOfClass.length;
			for (int i = 0; i < numClasses; i++) {
				Class<?> localClass = arrayOfClass[i];
				if (BaseColumns.class.isAssignableFrom(localClass)) {
					try {
						String str = (String) localClass.getDeclaredField(
								"TABLE_NAME").get(null);
						db.execSQL("DROP TABLE IF EXISTS " + str);
					} catch (Exception localException) {
						while (true)
							localException.printStackTrace();
					}
				}
				onCreate(db);

			}

		}
	}

	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean onCreate() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}
}
